const AuthService = require('../services/authService');
const logger = require('../config/logger');

class AuthController {
  static async register(req, res) {
    try {
      const result = await AuthService.register(req.body);
      // console.log('result',result)
      res.status(201).json(result);
    } catch (error) {
      logger.error(error);
      res.status(400).json({ message: error.message });
    }
  }

  static async login(req, res) {
    try {
      const { username, password } = req.body;
      const result = await AuthService.login(username, password);
      delete result.user.password;
      // console.log('result',result)
      res.json(result);
    } catch (error) {
      logger.error(error);
      res.status(401).json({ message: error.message });
    }
  }
}

module.exports = AuthController;